<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数" id="b1">
<input type="button" value="猜一猜" onclick="f()">
<div>
    <span id="d1"></span>
</div>
<script>
    //得到1-100的随机整数
    let x = parseInt(Math.random()*100)+1;
    let sum=0;
    function f(){
        sum++;
        if (b1.value>x){
            d1.innerText = "猜大了";
        }else if (b1.value<x){
            d1.innerText ="猜小了";
        }else{
            d1.innerText="猜对了"+"一共猜了:"+sum+"次";
        }
    }
</script>
</body>
</html>